#include<cstdio>
#include<string>
#include<iostream>
#include<map>
#include<set>
using namespace std;
set<string> s;
map<string,int> m;
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	int t;
	scanf("%d",&t);
	for(int i=1;i<=t;i++){
		string q,str;
		cin>>q>>str;
		bool x=1,lll=0;
		int y=0;
		string w;
		int r[5]={0};
		for(int j=0;j<str.size();j++){
			if((str[j]=='-')||(x&&str[j]=='0')||(y<3&&str[j]==':')||(y==3&&str[j]=='.')){
				lll=1;
				break;
			}
			if(str[j]>='0'&&str[j]<='9'){
				r[y]=r[y]*10+str[j]-'0';
				w+=str[j];
				x=0;
			}else{
				x=1;
				w+=str[j];
				y++;
			}
		}
		if(lll||r[0]>=256||r[1]>=256||r[2]>=256||r[3]>=256||r[4]>=65536){
			printf("ERR\n");
			continue;
		}
		if(q=="Server"){
			if(s.count(w)){
				printf("FAIL\n");
			}else{
				s.insert(w);
				m[w]=i;
				printf("OK\n");
			}
		}else{
			if(s.count(w)){
				printf("%d\n",m[w]);
			}else{
				printf("FAIL\n");
			}
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
